{extend name="platform/base" /}
{block name="resources"/}
<style>
p {
    margin: 6px 0 10px;
}
</style>

{/block}
{block name="main"}
<section class="panel panel-default">
	<header class="panel-heading font-bold"> 物流跟踪设置{$emconfig.value.type} </header>
	<div class="panel-body">
		<form class="form-horizontal">
			<div class="form-group">
				<label class="col-sm-2 control-label">接口名称</label>
				<div class="col-md-4" style="width:80%;">
					<select name="" id="type" class="form-control" style="width:30%;">
							<option value="1" {if $emconfig.value.type eq 1}selected{/if}>快递鸟</option>
					</select>
				</div>
			</div>
			<div id="Js-appid" {if condition="$emconfig.value.type neq 1 && $emconfig.value.type != null"}style="display:none;"{/if}>
				<div class="line line-dashed line-lg pull-in"></div>
				<div class="form-group">
					<label class="col-sm-2 control-label">APPID</label>
					<div class="col-md-4" style="width:80%;">
						<input type="text" class="form-control" id=appid value="{$emconfig.value.appid}" style="width:30%;">
						<p class="hint" style="color:#BBB;margin-top:10px;">快递鸟ID</p>
					</div>
				</div>
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<label class="col-sm-2 control-label">APPKEY</label>
				<div class="col-md-4" style="width:80%;">
					<input type="text" class="form-control" id="appkey" value="{$emconfig.value.appkey}" style="width:30%;">
					<p class="hint" style="color:#BBB;margin-top:10px;">应用密钥</p>
				</div>
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<label class="col-sm-2 control-label">说明</label>
				<div class="col-md-4" style="width:80%;">
					<p><a href="{if $emconfig.value.type neq 1}http://www.kuaidi100.com/{else/}http://www.kdniao.com/{/if}" id="apply_address"target="_brank" style="color:#0072D2;">点击申请</a></p>
					<p class="hint" style="color:#BBB;margin-top:10px;">点击进行申请</p>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">是否启用</label>
				<div class="col-md-4" style="width:80%;">
					<label class="radio-label"><input type="radio" name="is_use" value="1" {if condition="$emconfig['is_use'] eq 1"}checked="checked"{/if}>是</label> 
					<label class="radio-label"><input type="radio" name="is_use" value="0" {if condition="$emconfig['is_use'] eq 0"}checked="checked"{/if}>否</label>
				</div>
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<div class="col-sm-4 col-sm-offset-2">
					<a href="javascript:void(0);" onclick="setExpressConfigAjax()" class="btn btn-primary">提交</a>
				</div>
			</div>
		</form>
	</div>
</section>
<script>
$("#type").change(function(){
	
		$("#Js-appid").show();
		$("#apply_address").attr("href","http://www.kdniao.com/");

})	

function setExpressConfigAjax(){
	var type = $("#type").val();
	if(type == 1){
		var appid = $('#appid').val();
	}else{
		var appid = "";
	}
	var appkey = $('#appkey').val();
	var back_url = $(".back_url").text();
	var is_use = $("input[type='radio'][name='is_use']:checked").val();
	$.ajax({
		type:"post",
		url : "{:__URL('PLATFORM_MAIN/config/expressmessage')}",
		data : {
			"type" : type,
			"appid" : appid,
			"appkey":appkey,
			"back_url" : back_url,
			"is_use" : is_use
		},
		success : function(data){
			if(data['code'] > 0){
				showMessage('success', data["message"],"{:__URL('PLATFORM_MAIN/config/expressmessage')}");
			}else{
				showMessage('error', data["message"]);
			}
		}
	});
}

</script>
{/block}